<template>
  <div class="store">
    <el-container>
  <el-header>
    <h2>测试门店</h2>
      <!-- 门店名 -->
  </el-header>
  <el-container>
    <el-aside width="200px">
      <!-- 餐厅菜类 -->
      <el-col :span="24">
    <h2>菜品导航</h2>
    <el-menu default-active="2" class="el-menu-vertical-demo">
      <el-menu-item v-for="dishType in dishTypes" :key="dishType.dishTypeId" v-model="dishType.dishTypeId" @click="getDishs(dishType)">
        <span slot="title">{{dishType.dishTypeName}}</span>
      </el-menu-item>
    </el-menu>
  </el-col>
    </el-aside>
    <el-main>
      <el-container>
      <el-header>
        <div style="margin-top:10px">
          <el-form :inline="true" :model="dishMenuForm" class="demo-form-inline">
            <el-form-item label="查询菜品">
              <el-input v-model="dishMenuForm.content" placeholder="请输入菜名查找菜品"></el-input>
            </el-form-item>
                <el-button type="primary" @click="getHouseInfo(null)">查询</el-button>
          </el-form>
        </div>
      </el-header>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
      
    </el-main>
  </el-container>
</el-container>
  </div>
</template>

<script>

export default {
    data() {
      return {
        input: '',
        dishTypes:[],
        storeId:'1',
        dishTypeId:'',
        dishes:[],
        dishMenuForm:{
          content:'',
        },
      }
    },
    mounted() {
        this.$axios.get("http://localhost:8082/getDishTypeByStoreId",
        {
          params:{
            storeId:this.storeId,
          }  
        })
        .then(response =>{
            if(response.data.code!='200'){
              this.$message.error("获取菜品分类失败，请稍后再试");
            }else{
              this.dishTypes = response.data.data;
            }
        })
        .catch(error =>{
          this.$message.error("系统错误");
        })
    },
    methods:{
      getDishs(dishType){
        console.log(dishType.id)
        this.$axios.get("http://localhost:8082/getDishByDishTypeId",
        {
          params:{
            dishTypeId:dishType.id,
          }  
        })
        .then(response =>{
            console.log(response);
            if(response.data.code!='200'){
              this.$message.error("获取菜品失败，请稍后再试");
            }else{
              console.log(response.data);
              this.dishes=response.data;
              this.$router.push("/dishmenu");
            }
        })
        .catch(error =>{
          this.$message.error("系统错误");
        })
      }
    }
  }
</script>
<style>
  
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 30px;
  }
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 40px;
  }
</style>
